package com.huike.clues.utils;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.huike.clues.domain.dto.ImportResultDTO;
import com.huike.clues.domain.vo.TbClueExcelVo;
import com.huike.clues.service.ITbClueService;

public class ExcelListener extends AnalysisEventListener<TbClueExcelVo> {


    private ITbClueService tbClueService;


    private ImportResultDTO resultDTO;

    public ExcelListener() {
    }

    public ExcelListener(ITbClueService tbClueService) {
        this.tbClueService = tbClueService;
    }

    /**
     * 返回结果集对象
     * @return
     */
    public ImportResultDTO getResult(){
        return resultDTO;
    }


    //每次解析一行数据,执行一次
    @Override
    public void invoke(TbClueExcelVo data, AnalysisContext analysisContext) {
        //执行一次入库操作
        ImportResultDTO addTbclue = tbClueService.importCluesData(data);
        resultDTO.addAll(addTbclue);

    }
    //解析完所有数据后执行
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

}
